#pragma once
#include "rgb.h"

struct ID2D1Bitmap1;
struct IDWriteTextLayout;
struct ID2D1SolidColorBrush;
class BitmapCopyer {
public:
    BitmapCopyer();
    BitmapCopyer(const BitmapCopyer& copyer);
    ~BitmapCopyer();

    bool isValid() const;

    void free();

protected:
    ID2D1Bitmap1* bitmap = nullptr;

    friend class Label;
};

struct Rect { int x, y, width, height; };
class Bitmap : public BitmapCopyer {
public:
    // unicode
    bool load(const uchar* truetype, int width, int height, uint color, bool shadow);

    bool load(IDWriteTextLayout* pTextLayout, ID2D1SolidColorBrush* pBrush, ID2D1SolidColorBrush* pBrushBlack);

    bool load(int width, int height, const RGB888* texture);

    bool load(int width, int height, int row, int cel, const RGB888* texture);

    bool load(int width, int height, const uchar* indexs, const uchar* alphas, const RGB565* palatte);

    void render(int iframe, int x, int y, int x0, int y0, int width, int height, float alpha = 1.0f) const;

    void render(int x, int y, float alpha = 1.0f) const;

    void render1(int iframe, int x, int y, int width, int height) const;

    void render4(int x, int y, int x0, int y0, int width, int height) const;

    void render9(int x, int y, int width) const;

    void render9(int x, int y, int width, int height, int e) const;

public:
    int width, height, row, cel;
};